import tornado.ioloop
import tornado.web
import os


class MainHandler(tornado.web.RequestHandler):
    def get(self):
        num = 5
        person1 = {
            "name": "sunwukong",
            "age": 18
        }
        person2 = {
            "name": "zhubajie",
            "age": 25
        }
        _list = [1, 2, 3, 4]
        self.render("index.html", num=num, person=person1,
                    **person2, _list=_list)


def make_app():
    return tornado.web.Application(
        # 路由
        [
            (r"/", MainHandler),
        ],
        # 网页模板
        template_path=os.path.join(os.path.dirname(__file__), "templates")
    )


if __name__ == "__main__":
    app = make_app()
    app.listen(8888)
    tornado.ioloop.IOLoop.current().start()
